package algotithm.acwing.rangeofproblems.test905;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/28-23:26
 * @Title 905. 区间选点
 */
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(String.valueOf(reader.readLine()));
        ArrayList<int[]> list = new ArrayList<>();
        while (n-- > 0) {
            String[] num = reader.readLine().split(" ");
            int[] arr = new int[2];
            arr[0] = Integer.parseInt(num[0]);
            arr[1] = Integer.parseInt(num[1]);
            list.add(arr);
        }
        list.sort(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1,int[] o2) {
                return o1[0] - o2[0];
            }
        });

        int k = 1;
        for (int i = 1; i < list.size(); i++) {
            if (list.get(i)[0] > list.get(i-1)[1]) {
                k++;
            } else {
                list.get(i)[1] = Math.min(list.get(i)[1],list.get(i-1)[1]);
            }
        }
        writer.write(k + "\n");
        writer.flush();
        writer.close();
        reader.close();

    }

}
